﻿using System;
using System.ComponentModel;

namespace ApplicationGenerator.GeneratorMenu.Forms
{
    /// <summary>
    /// Konwerter na potrzeby property grida, wyświetlający url strony skojarzonej z elementem menu
    /// </summary>
    public class UrlSelectConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return base.CanConvertFrom(context, sourceType);
        }

        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                return true;
            }

            return base.CanConvertTo(context, destinationType);
        }

        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (value == null || !(value is string))
                {
                    return string.Empty;
                }

                return value;
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}